package com.xpu.pms.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.xpu.pms.comm.http.PageInfo;
import com.xpu.pms.comm.http.QueryPage;
import com.xpu.pms.comm.http.Respond;
import com.xpu.pms.mapper.BaseAreaMapper;
import com.xpu.pms.entity.BaseAreaEntity;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.beans.factory.annotation.Autowired;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import java.util.List;
/**
 * @author 徐立彬
 * @date 2019-11-22
 */
@RestController
@RequestMapping("base/area")
public class BaseAreaController {
    @Autowired
    BaseAreaMapper baseAreaMapper;
    
    @RequestMapping("/all")
    public List<BaseAreaEntity> all() {
        List<BaseAreaEntity> list = baseAreaMapper.selectList(new QueryWrapper<>());
        return list;
    }
    
    @RequestMapping("/add")
    public Respond add(@RequestBody BaseAreaEntity entity) {
        baseAreaMapper.insert(entity);
        return new Respond();
    }
    
    @RequestMapping("/update")
    public Respond update(@RequestBody BaseAreaEntity entity) {
        baseAreaMapper.updateById(entity);
        return new Respond();
    }
    
    @RequestMapping("/del")
    public Respond del(@RequestBody BaseAreaEntity entity) {
        baseAreaMapper.deleteById(entity.getId());
        return new Respond();
    }

    @RequestMapping("/page")
    public Respond page(@RequestBody QueryPage page) {
        IPage<BaseAreaEntity> result = baseAreaMapper.selectPage(page.toPage(), new QueryWrapper<>());
        PageInfo pi = new PageInfo(result);
        return new Respond().setPage(pi).setData(result.getRecords());
    }
}
